{include file="public/head" /}
<div class="layui-fluid" style="top: 1rem;">
    <div class="layui-row">
        <form action="" method="post" class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="role_name" class="layui-form-label">
                    <span class="x-red">*</span>角色名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="role_name" name="role_name" required="" lay-verify="required" autocomplete="off" class="layui-input" value="" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="nickname" class="layui-form-label">
                    <span class="x-red">*</span>昵称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="nickname" name="nickname" required="" lay-verify="required" autocomplete="off" class="layui-input" value="" >
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    拥有权限
                </label>
                <table class="layui-table layui-input-block">
                    <tbody>
                    {volist name="navArr" id="v"}
                    <tr>
                        <td>
                            <input type="checkbox" name="ids[]"  lay-skin="primary" lay-filter="father" title="{$v['nav']}" value="{$v['id']}">
                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                <span>{$v['nav']}</span><i class="layui-icon layui-icon-ok"></i>
                            </div>
                        </td>
                        <td>
                            <table>
                                {if condition="($v['wmenu'] neq '')"}
                                {volist name="v.wmenu" id="w"}
                                <tr>
                                    <td>
                                        <div class="layui-input-block">
                                            <input name="ids[]" lay-skin="primary" type="checkbox" title="{$w['nav']}" value="{$w['id']}"><div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                            <span>{$w['nav']}</span><i class="layui-icon layui-icon-ok"></i>
                                        </div>
                                        </div>
                                    </td>
                                    {if condition="(count($w['three']) > 0)"}
                                    <td>
                                        <div class="layui-input-block">
                                            {volist name="w.three" id="m"}
                                            <input name="ids[]" lay-skin="primary" type="checkbox" title="{$m['nav']}" value="{$m['id']}">
                                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                                <span>{$m['nav']}</span><i class="layui-icon layui-icon-ok"></i>
                                            </div>
                                            {/volist}
                                        </div>
                                    </td>
                                    {/if}
                                </tr>
                                {/volist}
                                {/if}
                            </table>

                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    描述
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="desc" name="remark" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">启用状态</label>
                <div class="layui-input-block">

                    <input type="radio" name="status" value="1" lay-skin="primary" title="开启" checked="checked" >
                    <input type="radio" name="status" value="0" lay-skin="primary" title="停用" >
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data){
            //发异步，把数据提交给php
            $.ajax({
                type: "POST",
                url: "{:getUrl()}Role/add",
                data: data.field,
                dataType: "json",
                success: function(data){
                    // consoloe.log(data);
                    if(data.code > 0)
                    {
                        layer.msg(data.msg, {icon: 6},function(){
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    }
                    else
                    {
                        layer.msg(data.msg,{icon: 5,time:1000});
                    }
                }
            });
            // layer.alert("增加成功", {icon: 6},function () {
            //     // 获得frame索引
            //     var index = parent.layer.getFrameIndex(window.name);
            //     //关闭当前frame
            //     parent.layer.close(index);
            // });
            return false;
        });
        form.on('checkbox(father)', function(data){
            if(data.elem.checked){
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render();
            }else{
                $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();
            }
        });
    });
</script>
</body>
</html>